<?php

namespace App\Http\Requests\System\SysDept;

use Illuminate\Foundation\Http\FormRequest;
use OpenApi\Attributes as OA;
use Illuminate\Validation\Rules\Enum;
use App\Enums\System\SysDept\{Status, DelFlag};

/**
* @create 2023-10-16 15:43:16
*/
#[OA\Schema(title: '部门表表单', required: [],)]
class SysDeptRequest extends FormRequest {

    #[OA\Property('dept_id', title: '部门id', type: 'string', example: '', description: '')]
    // #[OA\Property('parent_id', title: '父部门id', type: 'string', example: '', description: '')]
    // #[OA\Property('ancestors', title: '祖级列表', type: 'string', example: '', description: '')]
    // #[OA\Property('dept_name', title: '部门名称', type: 'string', example: '', description: '')]
    // #[OA\Property('order_num', title: '显示顺序', type: 'string', example: '', description: '')]
    // #[OA\Property('leader', title: '负责人', type: 'string', example: '', description: '')]
    // #[OA\Property('phone', title: '联系电话', type: 'string', example: '', description: '')]
    // #[OA\Property('email', title: '邮箱', type: 'string', example: '', description: '')]
    // #[OA\Property('status', title: '部门状态（0正常 1停用）', type: 'string', example: '', description: '')]
    // #[OA\Property('del_flag', title: '删除标志（0代表存在 2代表删除）', type: 'string', example: '', description: '')]
    // #[OA\Property('create_by', title: '创建者', type: 'string', example: '', description: '')]
    // #[OA\Property('create_time', title: '创建时间', type: 'string', example: '', description: '')]
    // #[OA\Property('update_by', title: '更新者', type: 'string', example: '', description: '')]
    // #[OA\Property('update_time', title: '更新时间', type: 'string', example: '', description: '')]
    public function rules() {       /* 'mobile' => 'required|regex:/^1\d{10}$/' */ 
        // ignore   : 'dept_id',
        // nullable : 'parent_id','ancestors','dept_name','order_num','leader','phone','email','status','del_flag','create_by','create_time','update_by','update_time',
        return [
            ...(request()->isMethod('put') ? ['dept_id' => ['required']] : []),
            // 'parent_id' => ['required'],
            // 'ancestors' => ['required'],
            // 'dept_name' => ['required'],
            // 'order_num' => ['required'],
            // 'leader' => ['required'],
            // 'phone' => ['required'],
            // 'email' => ['required'],
            // 'status' => ['required', new Enum(Status::class)],
            // 'del_flag' => ['required', new Enum(DelFlag::class)],
            // 'create_by' => ['required'],
            // 'create_time' => ['required'],
            // 'update_by' => ['required'],
            // 'update_time' => ['required'],
            // ...(config('admin.admin_catpcha') ? ['code' => 'required',] : []),
        ];
    }

    public function attributes() {  /* 'mobile' => '手机号' */ 
        return [
            'dept_id' => '部门id',
            'parent_id' => '父部门id',
            'ancestors' => '祖级列表',
            'dept_name' => '部门名称',
            'order_num' => '显示顺序',
            'leader' => '负责人',
            'phone' => '联系电话',
            'email' => '邮箱',
            'status' => '部门状态（0正常 1停用）',
            'del_flag' => '删除标志（0代表存在 2代表删除）',
            'create_by' => '创建者',
            'create_time' => '创建时间',
            'update_by' => '更新者',
            'update_time' => '更新时间',
        ];
    }

    public function messages() {    /* 'mobile.regex' => '手机号格式不对' */ 
        return [
            'status.Illuminate\Validation\Rules\Enum' => $this->attributes()['status'].' 值必须为: '. join(',', Status::values()),
            'del_flag.Illuminate\Validation\Rules\Enum' => $this->attributes()['del_flag'].' 值必须为: '. join(',', DelFlag::values()),
        ];
    }

}